package com.zhuoshi.Test;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.zhuoshi.bean.WdHtRoom;
import com.zhuoshi.mapper.WdHtRoomMapper;
import com.zhuoshi.service.WdRoomService;

import net.sf.json.JSONArray;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value={"classpath:conf/spring-mvc.xml","classpath:conf/spring-mybatis.xml"})
public class RoomTest {
	
	    @Autowired
	    private JedisPool jedisPool;//注入JedisPool
	    
	    @Autowired
	    private WdHtRoomMapper wdHtRoomMapper;//注入JedisPool

	    @Test
	    public void demo_set()
	    {
	    	List<WdHtRoom> list = wdHtRoomMapper.selectAll(null);
	    	
	    	JSONArray jsonArray = JSONArray.fromObject(list);
	    	
	         //获取ShardedJedis对象
	        Jedis jedis = jedisPool.getResource();
	        
	        jedis.flushAll();
	         //存入键值对
	        jedis.set("rooms", jsonArray.toString());
	         //回收ShardedJedis实例
	        jedis.close();
	        
	    }
}
